// pages/myAddress/myAddress.js
const app = getApp()

Page({

    data: {
      address:[],
      delFlag: false,
      useingId: 0
    },
    to(){
        wx.navigateTo({
          url: 'pages/myAddress/myAddress',
        })
    },
    button(){
      wx.navigateTo({
        url: '/pages/addMyAddress/addMyAddress',
      })
    },
    button1(){
      wx.navigateTo({
        url: '/pages/deleteAdress/deleteAdress',
      })
    },

    onLoad: function (options) {
      wx.request({
        url: 'https://www.woodymidnight.cn/BCUHelper/api/address/selectaddressbyid',
        method:'POST',
        data:{
          userId : app.data.userInfo.userid
        },
        header: { 'content-type': 'application/x-www-form-urlencoded' },
        success:e=>{
          console.log(e);
          this.setData({
            address: e.data.data
          })
        }
      })
    },

    onShow:function(e){
      this.onLoad();
    },

    delOpen:function(e){
      console.log(e);
      this.setData({
        delFlag: true,
        useingId: e.currentTarget.dataset.addid
      })
    },

    delClose:function(e){
      this.setData({
        delFlag : false,
        useingId: 0
      })
    },

    del:function(e){
      wx.request({
        url: 'https://www.woodymidnight.cn/BCUHelper/api/address/deletebyaddressId',
        method:'POST',
        data:{
          addressId : e.currentTarget.dataset.addid
        },
        header: { 'content-type': 'application/x-www-form-urlencoded' },
        success:e=>{
          this.setData({
            delFlag : false,
            useingId: 0
          })
          wx.showToast({
            title: '删除成功',
          })
          this.onLoad()
        }
      })
    }
})